
// ReSharper disable CppClangTidyModernizeUseNodiscard
#pragma once
#include "Material.h"
#include "Texture2D.h"
#include "Path.h"
#include "ShaderProgram.h"

class FCubeMaterial final
	: public FMaterial
{
private:

	// 木板纹理
	std::shared_ptr<FTexture2D> TextureBoard;

	// 笑脸
	std::shared_ptr<FTexture2D> TextureSmilingFace;

public:

	virtual bool Init() override
	{
		if (!FMaterial::Init())
		{
			return false;
		}

		Shader->SetLightingModel(ELightingModel::None);

		FTextureBuild Build;
		TextureBoard = Build.Build(FPath::BuildImgPath("container.jpg"), true);

		Build.Reset();
		TextureSmilingFace = Build.Build(FPath::BuildImgPath("awesomeface.png"), true);

		Shader->Use();

		Shader->SetInt("texture1", 0);
		Shader->SetInt("texture2", 1);

		return true;
	}

	virtual void Use() override
	{
		FMaterial::Use();

		TextureBoard->BindTextureUnit(0);
		TextureSmilingFace->BindTextureUnit(1);
	}

	const std::string& GetFsSrcCode() const override
	{
		static std::string CodeStr = R"(
			#version 410 core
			out vec4 FragColor;
			
			in vec3 ourColor;
			in vec2 TexCoord;
			
			uniform sampler2D texture1;
			uniform sampler2D texture2;
			
			void main()
			{
			     FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2);
			}
		)";

		return CodeStr;
	}

	const std::string& GetVsSrcCode() const override
	{
		static std::string CodeStr = R"(

			#version 410 core 
			
			layout (location = 0) in vec3 aPos;
			layout (location = 1) in vec3 aColor;
			layout (location = 2) in vec2 aTexCoord;
			
			out vec3 ourColor;
			out vec2 TexCoord;
			
			uniform mat4 model;
			uniform mat4 view;
			uniform mat4 projection;
			
			
			void main()
			{
			    gl_Position = projection *  view * model * vec4(aPos, 1.0);
			    ourColor = aColor;
			    TexCoord = vec2(aTexCoord.x, aTexCoord.y);
			}

		)";

		return CodeStr;
	}
};

